<template>
	<el-dialog title="项目问题反馈对话框" v-model="visible" customClass="customWidth" destroy-on-close @closed="$emit('closed')">
		<el-form :model="form" ref="dialogForm" label-width="100px" label-position="left">
			<el-form-item label="问题标题">{{form.title}}
			</el-form-item>
			<el-form-item label="问题类型">{{form.problemTypeName}}
			</el-form-item>
			<el-form-item label="问题描述">{{form.remark}}
			</el-form-item>
			<el-form-item label="相关附件">
				<attach-menu :attachIds="form.attachId" :roleFlag="3" :preview="true"></attach-menu>
			</el-form-item>
		</el-form>
		<el-divider content-position="center">回复列表</el-divider>
		<scTable ref="table" :data="replyList" row-key="recordId" stripe remoteSort remoteFilter>
			<el-table-column label="#" type="index" width="50"></el-table-column>
			<el-table-column label="回复内容" prop="remark" width="300" :show-overflow-tooltip="true"></el-table-column>
			<el-table-column label="相关附件" prop="attachId" width="200" :show-overflow-tooltip="true">
				<template #default="scope">
					<attach-menu :attachIds="scope.row.attachId" :roleFlag="3" :preview="true"></attach-menu>
				</template>
			</el-table-column>
			<el-table-column label="回复时间" prop="createTime" width="150"></el-table-column>
			<el-table-column label="回复人" prop="createUserName" width="100"></el-table-column>
		</scTable>
		<el-divider content-position="center">问题回复</el-divider>
		<el-form :model="repForm" :rules="rules" ref="dialogForm" label-width="100px" label-position="left">
			<el-form-item label="问题回复" prop="remark">
				<el-input v-model="repForm.remark" placeholder="问题回复" clearable type="textarea" maxlength="380"></el-input>
			</el-form-item>
			<el-form-item label="相关附件">
				<sc-upload-file :apiObj="apiObj" v-model="fileList" :data="{module:'project'}" :showFileList="false" @success="addNewFile">
					<el-button type="primary" icon="el-icon-upload">上传附件</el-button>
				</sc-upload-file>
				<attach-menu v-model:attachIds="repForm.attachId" :roleFlag="4" :preview="true"></attach-menu>
			</el-form-item>
		</el-form>
		<template #footer>
			<el-button @click="visible=false">取 消</el-button>
			<el-button type="primary" :loading="isSaveing" @click="submit()">保 存</el-button>
		</template>
	</el-dialog>

</template>
<script>
import AttachMenu from '@/views/module/attachMenu'
export default {
	emits: ['success', 'closed'],
	components: {AttachMenu},
	data() {
		return {
			visible: false,
			isSaveing: false,
			//所需数据选项
			fileList: [],
			replyList:[],
			apiObj: this.$API.file.attach.uploadFile,
			form: {
				title: '',
				problemTypeName: '',
				remark: '',
				attachId: '',
			},
			repForm:{
				problemId:'',
				attachId:'',
				remark:""
			},
			rules: {
				remark: [
					{required: true, message: '问题回复不能为空', trigger: 'blur'}
				]
			}
		}
	},
	mounted() {
	},
	methods: {
		//显示
		open() {
			this.visible = true;
			return this
		},
		submit() {
			this.$refs.dialogForm.validate(async (valid) => {
				if (valid) {
					this.isSaveing = true;
					var res=await this.$API.project.proProblemReply.insertProProblemReply.post(this.repForm);
					this.isSaveing = false;
					if (res.code == 200) {
						this.$emit('success')
						this.visible = false;
						this.$message.success("操作成功")
					} else {
						this.$alert(res.message, "提示", {type: 'error'})
					}
				}
			})
		},
		async getProblemReplyList(){
			var res=await this.$API.project.proProblemReply.getProblemReplyList.get({problemId:this.repForm.problemId});
			if (res.code == 200) {
				this.replyList = res.data;
			} else {
				this.$alert(res.message, "提示", {type: 'error'})
			}
		},
		addNewFile(res, file)
		{
			let tArr = this.repForm.attachId.split(",");
			tArr.push(res.data.attachId);
			this.repForm.attachId = tArr.join(",");
		},
		setData(data) {
			this.repForm.problemId = data.recordId
			this.form.title = data.title
			this.form.problemTypeName = data.problemTypeName
			this.form.remark = data.remark
			this.form.attachId = data.attachId
			this.getProblemReplyList();
		},
	}
}
</script>

<style>
.customWidth {
	width: 60%;
}
</style>
